/** @author mike **/
package Controllers;

import Persistence.DaoTemp;
import Models.Student;
import Views.FrmLogin;
import Views.Students.FrmStudentsMain;

public class Controller_MainWindow {
    private Student _loggedInStudent;
    
    private Controller_Login _loginController;
    private FrmLogin _loginWindow;
    private FrmStudentsMain _studentsMainWindow;
    
    private DaoTemp _dao;
    
    public Controller_MainWindow(DaoTemp dao)
    {
        _loginWindow = new FrmLogin();
        _loginController = new Controller_Login(_loginWindow, this);
        _loginWindow.SetController(_loginController);
        _studentsMainWindow = new FrmStudentsMain(this);
        
        _dao = dao;
    }
    
    public void Run()
    {
        _loginController.ShowLoginWindow();
    }
    
    public boolean CheckUser(String userName, char[] password)
    {
        boolean success = true;
        _loggedInStudent = _dao.LoadStudent(userName, password);
        
        if (_loggedInStudent == null)
        {
            success = false;//instead of bool here it could be a thrown exception
        }
        else
        {
            success = true;
            _studentsMainWindow.setVisible(true);
        }
        return success;
    }
    
    public void EnrollmentToCourses()
    {
        _studentsMainWindow.setVisible(false);
        Controller_Enrolment controller = new Controller_Enrolment(_dao);
        controller.Run();
    }
    
    public void ViewScheduledCourses()
    {
        _studentsMainWindow.setVisible(false);
        Controller_ScheduledCourses scheduledCourses = new Controller_ScheduledCourses(_dao);
        scheduledCourses.Run();
    }
    
    public void ViewGrades()
    {
        HideMainWindow();
        Controller_Grades grades = new Controller_Grades(_dao);
        grades.Run();
    }
    
    public void DownloadCourses()
    {
        HideMainWindow();
        Controller_DownloadCourses downloadCourses = new Controller_DownloadCourses(_dao);
        downloadCourses.Run();
    }
    
    public void DownloadAssignments()
    {
        HideMainWindow();
        Controller_DownloadAssignments downloadAssign = new Controller_DownloadAssignments(_dao);
        downloadAssign.Run();
    }
    
    public void UploadAssignments()
    {
        HideMainWindow();
        Controller_UploadAssignments upload = new Controller_UploadAssignments(_dao);
        upload.Run();
    }
    
    public void TakeTest()
    {
        HideMainWindow();
        Controller_TakeTest tests = new Controller_TakeTest(_dao);
        tests.Run();
    }

    private void HideMainWindow() {
        _studentsMainWindow.setVisible(false);
    }
            
}
